/**
 * @description  组合风险分解
 */
import React, { PureComponent } from 'react';
import { connect } from 'dva';
import { TreeChartsC } from '../../../../../../../comps';

class DecompositionMap extends PureComponent {
  constructor() {
    super();
    this.state = {
      chartsData: [],
    };
  }
  componentDidMount() {
    const { args } = this.props;
    this.getData(args);
  }
  UNSAFE_componentWillReceiveProps(nextProps) {
    const { args, timeStamp } = nextProps;
    if (JSON.stringify(args) !== JSON.stringify(this.props.args)) {
      this.getData(args);
    }
  }

  getData = (args) => {
    this.props.dispatch({
      type: 'portfolioRiskM/getDecompositionMap',
      payload: args,
      callback: (data) => {
        this.setState({
          chartsData: data || [],
        });
      },
    });
  };

  render() {
    return (
      <div>
        <TreeChartsC data={this.state.chartsData} height={400} legendName={['风险值', '超额风险值']} isPercent={true} />
      </div>
    );
  }
}
export default connect(({ portfolioRiskM }) => ({
  portfolioRiskM,
}))(DecompositionMap);
